

function submitUserData() {
  const data = {};
  data.name = $("#name").val();
  data.email = $("#email").val();
  data.password = $("#cpwd").val();
  var pwd = $('.pwd').eq(0).val();
var cpwd = $(".pwd").eq(1).val();


  // 验证用户名是否为空和两次输入的密码是够一致
  if ($("#name").val() == '' || undefined) {
    $('.error-block').eq(0).children('h3').html('username cannot be null.');
    $('.error-block').eq(0).fadeIn(800).delay(800).fadeOut(500);
  }
  else if (pwd == cpwd) {
    $.ajax({
      url: "/user/register",
      data: data,
      method: "POST",
      dataType: "JSON",
      success: function (res) {
        if (res.success) {
          location.replace("/views/loginPage.html");
        } else {
          console.log(res.msg);
          cl();
        }
      },
      error: function (err) {
        console.log("Got error " + err);
      },
    });
  } else if (pwd != cpwd) {
    $('.error-block').eq(0).children('h3').html('Please check the password not same. give same password.');
    $('.error-block').eq(0).fadeIn(1000).delay(1000).fadeOut(500);
  }
}

//  密码显示或隐藏
function showHidePwd() {
  const currentType = $(".pwd").attr("type");
  if (currentType == "password") {
    $(".pwd").attr("type", "text");
  } else {
    $(".pwd").attr("type", "password");
  }
}






// 提示弹出框
function cl() {
  var pop = document.querySelector("#pop-up-block");
  pop.style.display = "block";
  var covering = document.querySelector(".main-pop");
  covering.style.display = "block";

}
function ml() {
  var pop = document.querySelector("#pop-up-block");
  pop.style.display = "none";
  var covering = document.querySelector(".main-pop");
  covering.style.display = "none"
}
